package com.systemic.controller;

import com.systemic.core.ResponseResult;
import com.systemic.pojo.LoveBank;
import com.systemic.pojo.LoveBankCount;
import com.systemic.service.LoveBankService;
import com.systemic.vo.LoveBankInfo;
import com.systemic.vo.LoveBankLog;
import com.systemic.vo.PageVo;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.List;

/**
 * @ClassName: LoveBankController
 * @Description:
 * @Author:
 * @CreateTime: 2024-02-03 20:17
 * @Version:
 **/
@RestController
@RequestMapping("/loveBank")
public class LoveBankController {

    @Resource
    private LoveBankService loveBankService;

    /**
     * 存款
     * @param uid
     * @param fid
     * @param msg
     * @param img
     * @return
     */
    @PostMapping("/deposit")
    public ResponseResult<String> deposit(@RequestParam("uid") Integer uid,
                                          @RequestParam("fid") Integer fid,
                                          @RequestParam("msg") String msg,
                                          @RequestParam("img") MultipartFile img){
        LoveBank loveBank = new LoveBank();
        loveBank.setUid(uid);
        loveBank.setFid(fid);
        loveBank.setMsg(msg);
        loveBank.setTypesOf(1);
        int row = loveBankService.deposit(img, loveBank);
        return row!=0 ? ResponseResult.success("新增成功") : ResponseResult.failed("新增失败");
    }

    /**
     * 取款
     * @param uid
     * @param fid
     * @param msg
     * @param img
     * @return
     */
    @PostMapping("/withdraw")
    public ResponseResult<String> withdraw(@RequestParam("uid") Integer uid,
                                          @RequestParam("fid") Integer fid,
                                          @RequestParam("msg") String msg,
                                          @RequestParam("img") MultipartFile img){
        LoveBank loveBank = new LoveBank();
        loveBank.setUid(uid);
        loveBank.setFid(fid);
        loveBank.setMsg(msg);
        loveBank.setTypesOf(2);
        int row = loveBankService.withdraw(img, loveBank);
        return row!=0 ? ResponseResult.success("新增成功") : ResponseResult.failed("新增失败");
    }


    /**
     * 存取记录
     * @param pageVo
     * @return
     */
    @PostMapping("/selectList")
    public ResponseResult<List<LoveBankLog>> selectList(@RequestBody PageVo pageVo){
        List<LoveBankLog> res = loveBankService.selectList(pageVo);
        return !res.isEmpty() ? ResponseResult.success(res) : ResponseResult.failed("没有内容");
    }

    /**
     * 存取年统计
     * @param uid
     * @return
     */
    @GetMapping("/count/{uid}")
    public ResponseResult<LoveBankCount> count(@PathVariable("uid") Integer uid){
        LoveBankCount res = loveBankService.selectCount(uid);
        return res!=null ? ResponseResult.success(res) : ResponseResult.failed("没有内容");
    }

    /**
     * 存取款详情
     * @param id
     * @return
     */
    @GetMapping("/loveBankInfo/{id}")
    public ResponseResult<LoveBankInfo> loveBankInfo(@PathVariable("id") Integer id){
        LoveBankInfo res = loveBankService.loveBankInfo(id);
        return res!=null ? ResponseResult.success(res) : ResponseResult.failed("没有内容");
    }









}
